<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<c:import url="/includes/header.jsp"></c:import>
</head>
<body>


	<div class="container" id="order_container">
		<form id="listForm" method="post"
			action="${pageContext.request.contextPath}/admin/order/list.do">

			<div class="row">

				<c:if test="${empty shop }">
					<h3 class="alert alert-warning">*查询信息异常，请稍后再试</h3>
				</c:if>
				<c:if test="${not empty shop }">
					<table class="table table-bordered table-hover"
						style="text-align: left">
						<tr>
							<td height="20px"></td>
						</tr>
						<tr>
							<td>
								<div class="col-sm-2">发货:</div>
								<div class="col-sm-10">
									<span>${shop.address }</span>
								</div>

							</td>

						</tr>
						<tr>
							<td height="20px"></td>
						</tr>
						<tr>
							<td>
								<div class="col-sm-2">收货:</div>
								<div class="col-sm-8">
									<span>${order.consigness}【${order.phone}】</span>
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div class="col-sm-2">单价:</div>
								<div class="col-sm-2">${order.totalPrice}元</div>
								<div class="col-sm-4" style="float: right">
									<span>已付款</span>
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div class="col-sm-2">来源:</div>
								<div class="col-sm-4" style="float: right">
									<span>${order.type=='ele'?'饿了么':'美团外卖' } #${order.daySn}</span>
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div class="col-sm-2">配送费:</div>
								<div class="col-sm-4" style="float: right">
									<span id="fee">${order.deliverFee }元</span>
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div class="col-sm-2">小费:</div>
								<div class="col-sm-4" style="float: right">
									<span id="tips" data-orderId="${order.id}"
										data-fee="${order.deliverFee }">0</span>元<a
										class="btn btn-sm btn-default tips" data-type="-1">-</a><a
										class="btn btn-sm btn-default tips" data-type="1">+</a>
								</div>
							</td>
						</tr>
						<tr>
							<td height="20px"></td>
						</tr>
						<tr>
							<td>
								<div>
									<h4>合计费用${order.deliverFee }元</h4>
									<p class="alert alert-warning">*发布订单就代表您同意达达公司的相关规则和运费标准</p>
								</div>
							</td>
						</tr>
					</table>
				</c:if>
			</div>
		</form>
	</div>
</body>
</html>
<script type="text/javascript">
	$(function() {
		$("#btn-confirm")
				.click(
						function() {
							var tips = $("#tips").text();
							var orderId = $("#tips").attr("data-orderId");
							var fee = $("#tips").attr("data-fee");
							var data = {
								"orderId" : orderId,
								"tips" : tips,
								"fee" : fee
							};
							var url = '${pageContext.request.contextPath}/admin/order/deliver/send.do';
							$.ajax({
								type : "post",
								dataType : "json",
								data : data,
								url : url,
								async : false,
								success : function(data) {
									if (data.code == 0) {
										$('#myModal').modal('hide')
										bootbox.alert("发单成功");
									} else {
										bootbox.alert("网络不稳定,运行失败");
									}
								},
								error : function() {
									bootbox.alert("网络不稳定,运行失败");
								}
							});

						});

		$(".tips").bind("click", function() {
			var tipsType = $(this).attr("data-type");
			var tips = $("#tips").text();
			
			if (parseInt(tipsType) == -1 && parseInt(tips) == 0) {
				console.info(tipsType)
			} else {
				var value = parseInt(tips) + parseInt(tipsType);
				$("#tips").text(value);
			}
		});
	})
</script>
